package com.solocredit.finance.ui.user.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.solocredit.finance.R
import com.solocredit.finance.base.adapter.MullaRecyclerViewAdapter
import com.solocredit.finance.base.adapter.MullaViewHolderHelper
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/31 16:42
 * @Annotation：客服适配器
 */
class MullaKefuAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_mulla_kefu) {
    override fun setItemChildListener(helper: MullaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btnFun) //拨号、复制
    }

    override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.textValue,model.optString("value"))
        val imgType = helper.getImageView(R.id.imgType)
        val type = model.optString("type")
        when(type){
            "MOBILE" -> {//电话
                helper.setText(R.id.textTitle,String.format(mContext.getString(R.string.dialog_kefu_mobile_title),"${position + 1}"))
                helper.setText(R.id.textType,mContext.getString(R.string.dialog_kefu_dial))
                imgType.setImageResource(R.mipmap.mulla_kefu_mobile_icon)
                helper.setVisibility(R.id.btnFun,View.VISIBLE)
            }
            else -> {//邮箱
                helper.setText(R.id.textTitle,mContext.getString(R.string.dialog_kefu_email_title))
                helper.setVisibility(R.id.btnFun,View.GONE)
            }
        }

        if (position == itemCount - 1){
            helper.setVisibility(R.id.vLine, View.GONE)
        } else {
            helper.setVisibility(R.id.vLine, View.VISIBLE)
        }
    }
}